'use strict';

module.exports = {
  async up (queryInterface, Sequelize) {
    const { INTEGER, DATE } = Sequelize;
    await queryInterface.createTable('friend_tag', {
      id: {type: INTEGER(20).UNSIGNED, primaryKey: true, autoIncrement: true},
      friend_id: {type: INTEGER(20).UNSIGNED, allowNull: false, comment: '好友id',
        // 定义外键
        references: {
          model: 'friend',  // 对应表名称
          key: 'id' // 对应表的主键
        },
        onUpdate: 'restrict', // 更新时操作
        onDelete: 'cascade' // 删除时操作
      },
      tag_id: {type: INTEGER(20).UNSIGNED, allowNull: false, comment: '标签id',
        // 定义外键
        references: {
          model: 'tag',  // 对应表名称
          key: 'id' // 对应表的主键
        },
        onUpdate: 'restrict', // 更新时操作
        onDelete: 'cascade' // 删除时操作
      },
      created_at: DATE,
      updated_at: DATE
    });
    
  },

  async down (queryInterface, Sequelize) {
    await queryInterface.dropTable('friend_tag');
  }
};
